package org.example.service.impl;

import org.example.dao.UserDao;
import org.example.service.UserService;
import org.example.tools.JDBCTool;
import org.example.vo.Users;

import java.util.Collections;
import java.util.List;

public class UserServiceImpl implements UserService {
//    public static void main(String[] args) {
//        UserService userService = UserService.getInstance();
//        userService.queryUserList();
//        System.out.println(userService.queryUserList().get(2).getUsername());

//    }

    private UserDao userDao = UserDao.getInstance();

    @Override
    public Users userLogin(Users users) {
        System.out.println("执行了用户登录操作！！！");
        return userDao.userLogin(users);
    }

    @Override
    public List<Users> queryUserList(String username) {
        if(username!=null && !"".equals(username)){
            username = "%"+username+"%";
        }
//        System.out.println("成功调用");
        return userDao.queryUserList(username);
    }

    @Override
    public int insertUser(Users users) {
        int rows = 0;
        // 新增id是没有值的，更新id是有值
        if (users.getId()==null){
            rows = userDao.insertUser(users);
        }else {
            rows = userDao.updateUser(users);
        }
        return rows;
    }

    @Override
    public int deleteUser(String id) {
        return userDao.deleteUser(id);
    }

    @Override
    public Users queryUserById(String id) {
        return userDao.queryUserById(id);
    }
}
